import './css/index.css' // css文件会合并入头部的style内
import print from './print.js'

function component() {
	const ele = document.createElement('div')
	const btn = document.createElement('button')
	
	ele.innerHTML = ['Hello', 'webpack'].join(' ')
	ele.classList.add('theme')
	
	btn.innerText = 'click me for print'
	btn.onclick = function() {
		print('clicked button')
	}
	
	ele.appendChild(btn)
	return ele
}


// document.body.appendChild(component())
function updateElement() {
	let element = component()
	document.body.appendChild(element)
	if (module.hot) {
		module.hot.accept('./print.js', function() {
			console.log('Accept the update print.js module')
			// print()
			document.body.removeChild(element)
			element = component()
			document.body.appendChild(element)
		})
	}
}
updateElement()

